package com.captain.special.哈希表;

import java.util.*;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/4/4 14:57
 */
public class 两个数组的交集349 {

    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums1) {
            set.add(num);
        }
        ArrayList<Integer> arr = new ArrayList<>();
        Set<Integer> set2 = new HashSet<>();
        for (int num2 : nums2) {
            set2.add(num2);
        }
        for (Integer inRes : set2) {
            if (set.contains(inRes)) {
                arr.add(inRes);
            }
        }
        int[] arrRes = new int[arr.size()];
        for (int i = 0; i < arr.size(); i++) {
            arrRes[i] = arr.get(i);
        }
        return arrRes;
    }
}
